using System;
using System.Collections.Generic;
using System.Text;
using Mpi.Common.Collections;
using System.ComponentModel;

namespace Xeml.Document
{
    public class Partition : XemlAnnotatableObject
    {
        private int _id;
        private MaterialCollection _material;

        #region Properties
        public int Id
        {
            get { return _id; }
            set { _id = value; }
        }

        public MaterialCollection Material
        {
            get
            {
                return _material;
            }
        }

        private PositionCollection _positions;
        public PositionCollection Positions
        {
            get
            {
                return _positions;
            }
        }
        #endregion

        #region ctors
        public Partition()
        {
            this._material = new MaterialCollection(this);
            _positions = new PositionCollection(this);
        }

        public Partition(Partition p)
            : base(p)
        {
            this._material = new MaterialCollection(this);
            _positions = new PositionCollection(this);
            foreach (Term m in p.Material)
            {
                this._material.Add(new Term(m));

            }

            foreach (VariableTerm m in p.Positions)
            {
                this._positions.Add(new VariableTerm(m));

            }

            this._id = p.Id;
        }

        #endregion


        private PartitionCollection _collection;
        public PartitionCollection Collection
        {
            get
            {
                return this._collection;
            }
            set
            {
                if (value != _collection)
                {
                    this._collection = value;
                }

            }
        }

        public Sample GetSample()
        {
            StoryBase sb = this.Collection.Observation.Collection.ObservationPoint.Collection.Story;
            if (sb != null)
            {
                foreach (Sample s in sb.Samples)
                {
                    if (s.Partitions.Contains(this))
                    {
                        return s;
                    }
                }
            }
            return null;
        }
    }
}
